<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends Admin_Controller {
	
	private $id = PAGE_HOME_ID;
	
    function __construct() {
        parent::__construct();
    }

	public function index(){		
		$this->view();
	}
	
	public function view(){
		$data['data'] = $this->mod_page->getPageById($this->id);
		
		$data['title']	= 'Home';
		$data['page']	= 'page/home/view';
		$data['action']	= 'Home Page';
    	$this->load->view('layout/admin',$data);
	}
	
	public function edit(){
		if($this->input->post('btnSave')){
        	$this->form_validation->set_rules('description', 'Description', 'trim|required');
			
        	if ($this->form_validation->run() == TRUE) {
				$description = $this->input->post('description');
				
				if($this->mod_page->update($this->id, $description)){
					$this->session->set_userdata('ms', 'Successfully changed!');
				} else {
					$this->session->set_userdata('ms', 'Could not updated, please try again!');
				}
				redirect('page/home');
			}
		}
		$data['data'] = $this->mod_page->getPageById($this->id);
		
		$data['title']	= 'Edit Home Page';
		$data['page']	= 'page/home/edit';
		$data['action']	= 'Edit Home Page';
    	$this->load->view('layout/admin',$data);
	}
}
